﻿using System;
using System.Collections;

namespace YArchitech.HCLoad.XmlData
{
	public class WallDataTemplDict
	{
		public WallDataTemplDict(DataBase dataBase)
		{
			this.parent = dataBase;
			this.AddWhTempls();
			this.AddDefaultWallTempls();
		}

		public DataBase Parent
		{
			get
			{
				return this.parent;
			}
			set
			{
				this.parent = value;
			}
		}

		public Hashtable WhTempls
		{
			get
			{
				return this.whTempls;
			}
		}

		private void AddWhTempls()
		{
			try
			{
				this.whTempls = new Hashtable();
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
		}

		public int AddWhTempl(WhTempl whTempl)
		{
			int result;
			try
			{
				whTempl.Parent = this;
				int num = this.parent.AddCurrID();
				whTempl.ID = num;
				this.whTempls.Add(num, whTempl);
				this.parent.hCurrIDList.Add(num, whTempl);
				result = num;
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		public void RemoveWhTempl(int ID)
		{
			try
			{
				this.whTempls.Remove(ID);
				this.parent.hCurrIDList.Remove(ID);
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
		}

		public WhTempl GetWhTempl(int ID)
		{
			WhTempl result;
			try
			{
				result = (WhTempl)this.whTempls[ID];
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		public bool LoadWhTempl(WhTempl whTempl)
		{
			bool result;
			try
			{
				whTempl.Parent = this;
				int id = whTempl.ID;
				if (this.parent.hCurrIDList.ContainsKey(id))
				{
					result = false;
				}
				else
				{
					if (id > this.parent.CurrID)
					{
						this.parent.CurrID = id;
					}
					this.whTempls.Add(id, whTempl);
					this.parent.hCurrIDList.Add(id, whTempl);
					result = true;
				}
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		public Hashtable DefaultWallTempls
		{
			get
			{
				return this.defaultWallTempls;
			}
		}

		private void AddDefaultWallTempls()
		{
			try
			{
				this.defaultWallTempls = new Hashtable();
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
		}

		public void LoadDefaultWallTempls()
		{
			try
			{
				this.defaultWallTempls = new Hashtable();
				DefaultWallTempl defaultWallTempl = new DefaultWallTempl(this);
				defaultWallTempl.ID = 51;
				defaultWallTempl.Name = "屋面";
				this.defaultWallTempls.Add(defaultWallTempl.ID, defaultWallTempl);
				this.parent.hCurrIDList.Add(defaultWallTempl.ID, defaultWallTempl);
				defaultWallTempl = new DefaultWallTempl(this);
				defaultWallTempl.ID = 37;
				defaultWallTempl.Name = "天窗";
				this.defaultWallTempls.Add(defaultWallTempl.ID, defaultWallTempl);
				this.parent.hCurrIDList.Add(defaultWallTempl.ID, defaultWallTempl);
				defaultWallTempl = new DefaultWallTempl(this);
				defaultWallTempl.ID = 29;
				defaultWallTempl.Name = "外墙";
				this.defaultWallTempls.Add(defaultWallTempl.ID, defaultWallTempl);
				this.parent.hCurrIDList.Add(defaultWallTempl.ID, defaultWallTempl);
				defaultWallTempl = new DefaultWallTempl(this);
				defaultWallTempl.ID = 31;
				defaultWallTempl.Name = "外窗";
				this.defaultWallTempls.Add(defaultWallTempl.ID, defaultWallTempl);
				this.parent.hCurrIDList.Add(defaultWallTempl.ID, defaultWallTempl);
				defaultWallTempl = new DefaultWallTempl(this);
				defaultWallTempl.ID = 7;
				defaultWallTempl.Name = "内墙";
				this.defaultWallTempls.Add(defaultWallTempl.ID, defaultWallTempl);
				this.parent.hCurrIDList.Add(defaultWallTempl.ID, defaultWallTempl);
				defaultWallTempl = new DefaultWallTempl(this);
				defaultWallTempl.ID = 13;
				defaultWallTempl.Name = "内窗";
				this.defaultWallTempls.Add(defaultWallTempl.ID, defaultWallTempl);
				this.parent.hCurrIDList.Add(defaultWallTempl.ID, defaultWallTempl);
				defaultWallTempl = new DefaultWallTempl(this);
				defaultWallTempl.ID = 63;
				defaultWallTempl.Name = "楼板";
				this.defaultWallTempls.Add(defaultWallTempl.ID, defaultWallTempl);
				this.parent.hCurrIDList.Add(defaultWallTempl.ID, defaultWallTempl);
				defaultWallTempl = new DefaultWallTempl(this);
				defaultWallTempl.ID = 35;
				defaultWallTempl.Name = "外门";
				this.defaultWallTempls.Add(defaultWallTempl.ID, defaultWallTempl);
				this.parent.hCurrIDList.Add(defaultWallTempl.ID, defaultWallTempl);
				defaultWallTempl = new DefaultWallTempl(this);
				defaultWallTempl.ID = 17;
				defaultWallTempl.Name = "内门";
				this.defaultWallTempls.Add(defaultWallTempl.ID, defaultWallTempl);
				this.parent.hCurrIDList.Add(defaultWallTempl.ID, defaultWallTempl);
				this.parent.CurrID = 64;
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
		}

		public int AddDefaultWallTempl(DefaultWallTempl defaultWallTempl)
		{
			int result;
			try
			{
				defaultWallTempl.Parent = this;
				int num = this.parent.AddCurrID();
				defaultWallTempl.ID = num;
				this.defaultWallTempls.Add(num, defaultWallTempl);
				this.parent.hCurrIDList.Add(num, defaultWallTempl);
				result = num;
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		public void RemoveDefaultWallTempl(int ID)
		{
			try
			{
				this.defaultWallTempls.Remove(ID);
				this.parent.hCurrIDList.Remove(ID);
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
		}

		public void ClearDefaultWallTempl()
		{
			try
			{
				foreach (object obj in this.defaultWallTempls)
				{
					int num = int.Parse(((DictionaryEntry)obj).Key.ToString());
					this.parent.hCurrIDList.Remove(num);
				}
				this.defaultWallTempls.Clear();
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
		}

		public DefaultWallTempl GetDefaultWallTempl(int ID)
		{
			DefaultWallTempl result;
			try
			{
				result = (DefaultWallTempl)this.defaultWallTempls[ID];
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		public bool LoadDefaultWallTempl(DefaultWallTempl defaultWallTempl)
		{
			bool result;
			try
			{
				defaultWallTempl.Parent = this;
				int id = defaultWallTempl.ID;
				if (this.parent.hCurrIDList.ContainsKey(id))
				{
					result = false;
				}
				else
				{
					if (id > this.parent.CurrID)
					{
						this.parent.CurrID = id;
					}
					this.defaultWallTempls.Add(id, defaultWallTempl);
					this.parent.hCurrIDList.Add(id, defaultWallTempl);
					result = true;
				}
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		private DataBase parent;

		private Hashtable whTempls;

		private Hashtable defaultWallTempls;
	}
}
